<?php

namespace app\admin\model;

use think\Model;

class LoanCompany extends Model
{
    // 表名
    protected $name = 'loan_company';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'cate_id_text'
    ];
    

    
    public function getCateIdList()
    {
        return ['1' => __('Cate_id 1'),'2' => __('Cate_id 2'),'3' => __('Cate_id 3')];
    }     


    public function getCateIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['cate_id'];
        $valueArr = explode(',', $value);
        $list = $this->getCateIdList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }

    protected function setCateIdAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }


}
